<template>
  <div class="touzilist">
    <el-card>
      <el-row>
        <el-table :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" style="width: 100%" border>
          <el-table-column :index="indexMethod" type="index" label="序号" width="50"></el-table-column>
          <el-table-column label="课程名称" align="center" width="200">
            <template slot-scope="scope">
              <span>{{ scope.row.cname}}</span>
            </template>
          </el-table-column>
          <el-table-column label="课程图片" align="center" width="180">
            <template slot-scope="scope">
          <span v-if="scope.row.img == null || scope.row.img === ''">
            <el-image
              class="table-td-thumb"
              style="width: 80px; height: 80px"
              src="http://localhost:8080/CourseHead/zwtp.png"
            ></el-image>
          </span>
              <span v-else>
            <el-image
              class="table-td-thumb"
              style="width: 80px; height: 80px"
              :src="scope.row.img"
              :preview-src-list="[scope.row.img]"
            ></el-image>
          </span>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center" width="180">
            <template slot-scope="scope">
              <span style="color:rgb(0, 208, 83)">{{scope.row.cdate  | dataFormat}}</span>
            </template>
          </el-table-column>
          <el-table-column label="课程类型" align="center" width="110">
            <template slot-scope="scope">
              <span v-if=" scope.row.level==='1'">专升本课程</span>
              <span v-else-if="scope.row.level==='2'">高升本课程</span>
              <span v-else>高升专课程</span>
            </template>
          </el-table-column>
          <el-table-column label="面向类型" align="center" width="110">
            <template slot-scope="scope">
              <span v-if="scope.row.cway=='1'">函授类型</span>
              <span v-else>业余类型</span>
            </template>
          </el-table-column>
          <el-table-column label="课程审核状态" align="center" width="120">
            <template slot-scope="scope">
              <span v-if="scope.row.isverify==1">已审核</span>
              <span v-else-if="scope.row.isverify==0" style="color: #fc0d6f">未审核</span>
            </template>
          </el-table-column>
          <el-table-column label="价格" align="center" width="80">
            <template slot-scope="scope">
              <span>{{ scope.row.cvalue}}</span>
            </template>
          </el-table-column>
          <el-table-column label="销售数量" align="center" width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.sale}}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="86">
            <template slot-scope="scope">
              <el-tooltip
                class="item"
                effect="dark"
                content="查看详情"
                :enterable="false"
                placement="top"
                v-if="scope.row.sale!== 0">
                <el-button circle icon="el-icon-search" type="primary" v-on:click="getCourseSale(scope.row.cid)"></el-button>
              </el-tooltip>
              <el-tooltip
                class="item"
                effect="dark"
                content="课程暂无人购买"
                :enterable="false"
                placement="top"
                v-else>
                <el-button circle icon="el-icon-search"></el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <el-dialog title="销售详情" :visible.sync="dialogTableVisible" width="55%" >
        <el-table :data="formData" >
          <el-table-column type="index" label="序号" align="center"></el-table-column>
          <el-table-column property="name" label="姓名" width="160"  align="center"></el-table-column>
          <el-table-column label="购买日期" width="180">
            <template slot-scope="scope">
              <span>{{scope.row.buydate | dataFormat}}</span>
            </template>
          </el-table-column>
          <el-table-column property="tele" label="联系方式" width="200"  align="center"></el-table-column>
          <el-table-column property="email" label="邮箱"width="200" align="center"></el-table-column>
        </el-table>
      </el-dialog>
      <!--分页组件-->
      <div style="text-align: center;margin-top: 30px;">
        <el-pagination
          background
          layout="prev, pager, next"
          :page-size="pagesize"
          :total="total"
          :current-page="currentPage"
          @current-change="current_change">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        tableData: [],
        total: 0,
        pagesize: 4,
        currentPage:1,
        dialogTableVisible: false,
        formData: []
      };
    },
    methods: {
      current_change(val){
        this.currentPage = val;
        console.log(val);
        console.log(this.currentPage);
        // console.log(this.tableData);
      },
      getCourseSale(cid){
        this.$axios
          .get("/getSaleStudent",{
            params:{
              cid:cid
            }
          }).then(res =>{
          this.formData = res.data.data;
          this.dialogTableVisible = true;
        })
      },
      getTabsList() {
        this.$axios
          .get("/getsalespreview", {
            params:{
              tid: sessionStorage.getItem("uid")
            }
          })
          .then(res => {
            //			console.log(res)
            const data = res.data;
            this.tableData = data.data;
            this.total = res.data.data.length;
            console.log(this.tableData)
          });
      },

      indexMethod(index){
        return (this.currentPage-1)*this.pagesize+index+1;
      }
    },
    mounted() {
      this.getTabsList();
      console.log(this.tableData);
    },
  }
</script>

<style scoped>
  .touzilist {
    margin: 10px;
  }
  .elrow{
    margin-bottom: 20px;
  }
</style>
